#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100005;
ll n,m,l,mxv;
ll d[N],v[N],a[N],p[N];
int check(int i){
    //double dis=(mxv*mxv-v[i]*v[i])/(2*a[i]);
    if(v[i]<=mxv&&a[i]<=0)return 0;
    if(a[i]==0)return (v[i]>mxv);
    else if(a[i]<0){
        //<<"<"<<endl;
        //cout<<mxv*mxv-v[i]*v[i]<<"/"<<2*a[i]<<endl;
        if(v[i]<mxv)return 0;
        for(int j=1;j<=m;j++){
            if(p[j]>d[i]){
                //cout<<p[i]-d[j]<<endl;
                if((p[j]-d[i])*(2ll*a[i])>mxv*mxv-v[i]*v[i])return 1;
                return 0;
            }
        }
        return 0;
    }
    else{
        //cout<<">"<<endl;
        //cout<<mxv*mxv-v[i]*v[i]<<"/"<<2*a[i]<<endl;
        //double dis=(mxv*mxv-v[i]*v[i])/(2*a[i]);
        if(d[i]>p[m])return 0;
        if(d[i]==p[m]&&v[i]>mxv)return 1;
        if((p[m]-d[i])*(2ll*a[i])>mxv*mxv-v[i]*v[i])return 1;
        return 0;
    }
}//ok
int ans2=0;
void solve1(){
    int ans1=0;
    for(int i=1;i<=n;i++){
        if(check(i))ans1++;
    }
    cout<<ans1<<" ";
    //dfs(1);
    cout<<ans2<<endl;
}
void solve2(){
    int ans1=0;
    for(int i=1;i<=n;i++)if(v[i]>mxv&&d[i]<=p[m])ans1++;
    if(ans1==0)m++;
    cout<<ans1<<" "<<m-1<<endl;
}//ok
void solve3(){
    int ans1=0;
    for(int i=1;i<=n;i++){
        if(check(i))ans1++;
    }
    cout<<ans1<<" "<<m-1<<endl;
}//ok
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;scanf("%d",&t);
    while(t--){
        int ifA=1,ifB=1,ifC=1;
        scanf("%lld%lld%lld%lld",&n,&m,&l,&mxv);
        for(int i=1;i<=n;i++){
            scanf("%lld%lld%lld",&d[i],&v[i],&a[i]);
            if(a[i]!=0)ifA=0;
            if(a[i]<=0)ifB=0;
        }
        for(int i=1;i<=m;i++)cin>>p[i];
        if(n<=20)solve1();
        else if(ifA)solve2();
        else if(ifB)solve3();
    }
    return 0;
}//20+20
